home *** CD-ROM | disk | FTP | other *** search
- Path: news.umbc.edu!not-for-mail
- From: schlein@umbc.edu (Jonas J. Schlein)
- Newsgroups: comp.lang.c
- Subject: Re: Pointer Conversion
- Date: 21 Jan 1996 12:44:37 -0500
- Organization: University of Maryland Baltimore County
- Message-ID: <4dtu25$bgu@umbc9.umbc.edu>
- References: <4ds4jq$fo4@su3.in.net> <4ds6s3$ft6@su3.in.net>
- NNTP-Posting-Host: umbc9.umbc.edu
- NNTP-Posting-User: schlein
-
- Sam Pounds <poundss@in.net> wrote:
- |> Sorry, it just dawned on me.
- |> char *done = (char *)malloc(1024);
- |>
- |> But if anyone could tell me how I could just alloc the
- |> necessary memory for the two pointers I would appreciate it.
- |> Sorry again.
-
- Well drop the unnecessary cast while making sure you #include <stdlib.h>.
- Then do:
-
- char *done = malloc (strlen (a) + strlen (b) + 1);
-
- That will give you only as much space as you need with no room to spare.
- Make sure you verify that malloc() does not return NULL.
- --
- "If it wasn't for C, we would be using BASI, PASAL, and OBOL."
-
- Jonas J. Schlein (schlein@gl.umbc.edu)
-